package com.rf.richfitwheel.outbill.controller;


import com.rf.richfitwheel.admin.sys.vo.UserVO;
import com.rf.richfitwheel.admin.utils.UserUtil;
import com.rf.richfitwheel.common.utils.StringUtils;
import com.rf.richfitwheel.outbill.model.AcceptBillInfo;
import com.rf.richfitwheel.outbill.model.OutBillInfo;
import com.rf.richfitwheel.outbill.param.AcceptBillInfoParam;
import com.rf.richfitwheel.outbill.service.AcceptBillInfoService;
import com.rf.richfitwheel.utils.PageJson;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author admin
 * @since 2024-06-12
 */
@RestController
@RequestMapping("/outbill/acceptBillInfo")
@Api(tags = "提示承兑")
public class AcceptBillInfoController {

    @Autowired
    private AcceptBillInfoService acceptBillInfoService;

    /**
     * 通过ID查询信息
     *
     * @param id
     * @return
     */
    @GetMapping("/detail/{id}")
    @ApiOperation("提示承兑详情")
    public AcceptBillInfo detail(@PathVariable @ApiParam("主键id") String id) {
        QueryWrapper<AcceptBillInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", id);
        queryWrapper.select(AcceptBillInfo.class, v -> !(v.getColumn().equals("update_time") || v.getColumn().equals("create_time")));
        AcceptBillInfo acceptBillInfo = acceptBillInfoService.getOne(queryWrapper);
        return acceptBillInfo;
    }

    /**
     * 分页查询信息
     *
     * @param
     * @return
     */
    @ApiOperation("分页查询")
    @PostMapping ("/page")
    public PageJson getPageList(@RequestBody AcceptBillInfoParam acceptBillInfo) {
        return acceptBillInfoService.pageJson(acceptBillInfo);
    }

    /**
     * 出票登记作废
     */
    @ApiOperation("出票登记作废")
    @GetMapping("/cancel/{id}")
    public Boolean cancel(@PathVariable("id") @ApiParam("主键id") String id) {
        QueryWrapper<AcceptBillInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", id);
        AcceptBillInfo acceptBillInfo = acceptBillInfoService.getOne(queryWrapper);
        acceptBillInfo.setApvst("6");
        return acceptBillInfoService.updateById(acceptBillInfo);
    }

    /**
     * 添加
     * @param acceptBillInfo
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("提示承兌暫存")
    public boolean save(@RequestBody AcceptBillInfo acceptBillInfo) {
        acceptBillInfo.setApvst("2");
        UserVO user = UserUtil.getUser();
        acceptBillInfo.setCreateName(user.getStaffName());
        acceptBillInfo.setUpdateName(user.getStaffName());
        if(StringUtils.isNotBlank(acceptBillInfo.getId())){
            return acceptBillInfoService.updateById(acceptBillInfo);
        }else{
            return acceptBillInfoService.save(acceptBillInfo);
        }
    }

    /**
     * 提示承兑走流程
     *
     * @param outBillInfo
     * @return
     */
    @PostMapping("/addFlow")
    @ApiOperation("提示承兑提交接口")
    public boolean addFlow(@RequestBody @ApiParam("param传acceptBillInfo和wfTaskParam对象") Map<String, Object> params) {
        return acceptBillInfoService.addFlow(params);
    }

    /**
     * 撤销提示承兑走流程
     *
     * @param acceptBillInfo
     * @return
     */
    @PostMapping("/backFlow")
    @ApiOperation("撤回提示承兑提交接口")
    public boolean backFlow(@RequestBody @ApiParam("param传acceptBillInfo和wfTaskParam对象") Map<String, Object> params) {
        return acceptBillInfoService.backFlow(params);
    }

    /**
     * 提示承兌更新走流程
     *
     * @param modifyFlow
     * @return
     */
    @PostMapping("/modifyFlow")
    @ApiOperation("提示承兌更新方法，审批人走流程使用")
    public boolean modifyFlow(@RequestBody @ApiParam("param传acceptBillInfo和wfTaskParam对象") Map<String, Object> params) {
        return acceptBillInfoService.modifyFlow(params,UserUtil.getUser());
    }

    /**
     * 撤销提示承兌更新走流程
     *
     * @param modifyFlow
     * @return
     */
    @PostMapping("/backModifyFlow")
    @ApiOperation("撤销提示承兌更新方法，审批人走流程使用")
    public boolean backModifyFlow(@RequestBody @ApiParam("param传acceptBillInfo和wfTaskParam对象") Map<String, Object> params) {
        return acceptBillInfoService.backModifyFlow(params,UserUtil.getUser());
    }

    /**
     * 修改
     * @param acceptBillInfo
     * @return
     */
    @PostMapping("/modify")
    public boolean modify(@RequestBody AcceptBillInfo acceptBillInfo) {
        return acceptBillInfoService.updateById(acceptBillInfo);
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @PostMapping("/del")
    public boolean delBatch(@RequestParam("ids") List<String> ids) {
        return acceptBillInfoService.removeByIds(ids);
    }
}
